package com.econ.powercloud.ems.service.biz;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.econ.powercloud.common.base.facade.pojo.PageResult;
import com.econ.powercloud.ems.dal.entity.EmsEnergyEquipment;
import com.econ.powercloud.ems.domain.EmsEnergyEquipmentDO;
import com.econ.powercloud.ems.pojo.ApiDataVO;
import com.econ.powercloud.ems.pojo.EmsEnergyEquipmentVO;
import com.econ.powercloud.ems.service.dao.EmsEnergyEquipmentDAO;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author : zjf
 * @Description : 储能装置Service
 * @Date : 2021/7/28 17:52
 * @Modified by : zjf
 */
@Service
public class EnergyEquipmentService{

    @Autowired
    private EmsEnergyEquipmentDAO emsEnergyEquipmentDAO;

    public PageResult<List<ApiDataVO>> getEquipmentByEnergyStationId(String energyStationId, Integer pageNo, Integer pageSize) {
        Page<EmsEnergyEquipment> emsEnergyEquipmentPage = emsEnergyEquipmentDAO.selectListByStationId(energyStationId, pageNo, pageSize);
        List<ApiDataVO> apiDataVOS = Lists.newArrayList();
        for (EmsEnergyEquipment equipment : emsEnergyEquipmentPage.getRecords()) {
            apiDataVOS.add(ApiDataVO.builder().code(equipment.getEnergyEquipmentId()).name(equipment.getEnergyEquipmentName()).build());
        }
        return PageResult.<List<ApiDataVO>>builder().data(apiDataVOS)
                .pageNo((int)emsEnergyEquipmentPage.getCurrent()).totalCount((int)emsEnergyEquipmentPage.getTotal()).build();
    }

    public EmsEnergyEquipmentVO selectByStationIdAndEquipmentId(String energyStationId, String energyEquipmentId){
        EmsEnergyEquipment emsEnergyEquipment = emsEnergyEquipmentDAO.selectByStationIdAndEquipmentId(energyStationId, energyEquipmentId);
        EmsEnergyEquipmentVO result = EmsEnergyEquipmentDO.entityToVO(emsEnergyEquipment);
        return result;
    }

}
